<%@ page language="java" contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.nastation.pm.business.*"%>
<%@ page import="com.nastation.pm.bean.*"%>
<%@ page import="com.nastation.pm.util.*"%>
<%
	ProjectCategoryBO rb = new ProjectCategoryBO();
	String name = request.getParameter("name");
	System.out.println(name);
	String desc = request.getParameter("desc");
	int id = Integer.parseInt(request.getParameter("id"));

	//检查参数
	boolean hasError = false;
	String errMsg = "";
	if (StringUtils.isBlank(name)) {
		hasError = true;
		errMsg += "<li>Project Category name can't be empty!</li>";
	}

	if (rb.exists(name)) {
		ProjectCategory category = rb.getProjectCategory(id);
		String toName = category.getName();
		if (toName.equals(name)) {
		} else {
			hasError = true;
			errMsg += "<li><font color='red'>Project Name or Key already exists!</font></li>";
			request.setAttribute("error", errMsg);
			System.out.println(errMsg);
		}
	} else {
		ProjectCategory category = new ProjectCategory();
		category.setId(id);
		category.setName(name);
		category.setDescription(desc);
		rb.updateCategory(category);
	}
	if (hasError) {
%>
<jsp:include page="updateCategory.jsp"></jsp:include>
<%
	} else {
%>
<jsp:include page="viewProjectCategory.jsp"></jsp:include>
<%
	}
%>
